<template>
<!-- 端网业不匹配明细 -->
  <van-list
    v-model="loading"
    loading-text="加载中"
    :finished="finished"
    finished-text="没有更多了"
    @load="onload"
  >
    <div class="detail-info" v-for="(item,index) in list" :key="index">
      <div>
        <div class="info-detail">
          <span class="info-name">{{ item.DEVICE_NUMBER }}</span>
          <span class="info-flag">{{ item.USER_STATUS_DESC }}</span>
        </div>
        <div class="info-desc">产品：{{ item.PRODUCT_DESC }}</div>
        <div class="info-desc">入网时间：{{ item.INNET_DATE }}</div>
        <div class="info-desc">装机地址：{{ item.INS_ADDR }}</div>
      </div>
    </div>
  </van-list>
</template>

<script>
import { Toast } from 'vant'
import { warnDwyDetail } from '@/api/publicline/board.js'

export default {
  components: {},
  data() {
    return {
      dayId: '',
      queryParams: {
        pageNum: 1,
        pageSize: 15
      },
      loading: false,
      finished: false,
      list: [],
    }
  },
  created() {
    this.dayId = this.$route.query.dayId
    this.loadData()
  },
  beforeDestroy() {
    Toast.clear()
  },
  methods: {
    async loadData(force) {
      // 改变搜索条件，重新查询
      if ( force ) {
        this.queryParams.pageNum = 1
        this.list = []
        this.finished = false
      }
      this.loading = true
      const res = await warnDwyDetail({ ...this.queryParams, dayId: this.dayId, gridId: this.$dataPermission })
      const { result, success } = res
      if(success) {
        this.loading = false
        if(result.list.length < this.queryParams.pageSize) {
          this.finished = true
          Toast({
            message: '已全部加载',
            duration: 500,
            position: 'bottom',
            forbidClick: 'true'
          });
        }
        this.list = this.list.concat(result.list)
        Toast.clear()
      }
    },
    onload() {
      this.loading = false
      if(this.finished === false) {
        Toast({
          type:'loading',
          duration: 0,
          message: '正在加载',
          position: 'bottom',
          forbidClick: 'true'
        })
        this.queryParams.pageNum = parseInt(this.queryParams.pageNum) + 1
        this.loadData()
      } else {
        Toast({
          message: '已全部加载',
          duration: 500,
          position: 'bottom',
          forbidClick: 'true'
        })
      }
    },
  }
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/person.less';
</style>